package jnpf.database.sql.impl;

import jnpf.database.enums.DbAliasEnum;
import jnpf.database.enums.DbSttEnum;
import jnpf.database.source.DbBase;
import jnpf.database.sql.SqlBase;

/**
 * 达梦 SQL语句模板
 *
 * @author JNPF开发平台组
 * @version V3.2.0
 * @copyright 引迈信息技术有限公司
 * @date 2021/10/19
 */
public class SqlDM extends SqlBase {

    @Override
    protected void setSqlBase() {
        fieldListSql =
                    "select distinct A.column_name AS "+ DbAliasEnum.FIELD_NAME.AS() + "," +
                    " A.data_type AS "+DbAliasEnum.DATA_TYPE.AS()+", " +
                    "A.data_length AS "+DbAliasEnum.DATA_LENGTH.AS()+"," +
                    "case A.nullable when 'N' then '1' else '0' end AS "+DbAliasEnum.PRIMARY_KEY.AS()+"," +
                    "case A.nullable when 'N' then '0' else '1' end AS "+DbAliasEnum.ALLOW_NULL.AS()+"," +
                    "B.comments AS "+DbAliasEnum.FIELD_COMMENT.AS()+" from user_tab_columns A " +
                    "left join user_col_comments B on " +
                    "A.table_name=B.table_name and A.column_name=B.column_name " +
                    "where A.table_name = '"+ DbSttEnum.TABLE.getTarget() +"'";
        tableListSql =
                    "SELECT\n" +
                    "ut.TABLE_NAME " + DbAliasEnum.TABLE_NAME.AS() + ",utc.COMMENTS " + DbAliasEnum.TABLE_COMMENT.AS() + "\n" +
                    ",0 " + DbAliasEnum.TABLE_SUM.AS() + "\n" +
                    "FROM ALL_TABLES AS ut\n" +
                    "LEFT JOIN\n" +
                    "all_tab_comments AS utc\n" +
                    "ON\n" +
                    "ut.TABLE_NAME = utc.TABLE_NAME AND ut.OWNER = utc.OWNER\n" +
                    "WHERE ut.OWNER = '" + DbSttEnum.DB_SCHEMA.getTarget() + "'\n" +
                    "ORDER BY F_TABLE_NAME;";
    }

    @Override
    public String[] getPageSql(String sql, String sortType, Integer currentPage, Integer pageSize) {
        return new String[0];
    }

    public SqlDM(DbBase dbBase){
        super(dbBase);
    }

}
